package hn.cch.kafka.configuration;

import hn.cch.kafka.listener.BatchListener;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.annotation.EnableKafka;
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
import org.springframework.kafka.config.KafkaListenerContainerFactory;
import org.springframework.kafka.core.ConsumerFactory;
import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
import org.springframework.kafka.listener.ContainerProperties;
import org.springframework.kafka.listener.GenericMessageListener;

import java.util.List;

@EnableKafka
@Configuration
public class KafkaConfiguration {


    // @Bean
    // public KafkaListenerContainerFactory<?> containerFactory(KafkaProperties kafkaProperties) {
    //     ConcurrentKafkaListenerContainerFactory<String, String> containerFactory = new ConcurrentKafkaListenerContainerFactory<>();
    //     containerFactory.setConsumerFactory(new DefaultKafkaConsumerFactory<>(kafkaProperties.buildConsumerProperties()));
    //     containerFactory.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL_IMMEDIATE);
    //     return containerFactory;
    // }

    //
    // @Bean
    // public ConcurrentKafkaListenerContainerFactory<String, String> containerFactory(ConsumerFactory<String, String> consumerFactory) {
    //     ConcurrentKafkaListenerContainerFactory<String, String> containerFactory = new ConcurrentKafkaListenerContainerFactory<>();
    //     containerFactory.setConsumerFactory(consumerFactory);
    //     containerFactory.setBatchListener(true);
    //     containerFactory.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL_IMMEDIATE);
    //     return containerFactory;
    // }


    // @Bean
    // public GenericMessageListener<List<ConsumerRecord<String, String>>> batchLister() {
    //     return new BatchListener();
    // }





}
